﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BeniBastanYaratWinFormProject
{
    public partial class SatisGunlukRapor : Form
    {

        dbbaglantiDataContext db = new dbbaglantiDataContext();
        public SatisGunlukRapor()
        {
            InitializeComponent();
        }

        private void SatisGunlukRapor_Load(object sender, EventArgs e)
        {

            TabloyuDoldur();


        }

        private void TabloyuDoldur()
        {
            DateTime nextday = dateFiltre.Value.AddDays(1);
            DateTime baslangic = new DateTime(dateFiltre.Value.Year, dateFiltre.Value.Month, dateFiltre.Value.Day, 0, 0, 0);
            DateTime bitis = new DateTime(nextday.Year, nextday.Month, nextday.Day, 0, 0, 0);


            var sorgu = from x in db.Satislars
                        where (x.satıstarih >= baslangic && x.satıstarih < bitis)
                        join y in db.Urunlers on x.urunid equals y.UrunID into adim1
                        from k in adim1
                        select new
                        {
                            k.UrunAdi,
                            x.adet,
                            x.satıstarih,
                            x.toplamfiyat


                        };

            gridRapor.DataSource = sorgu;

            decimal? toplam = 0;
            foreach (var item in sorgu)
            {
                toplam += item.toplamfiyat;
            }
            lblToplamSatis.Text = sorgu.Count().ToString();
            lblCiro.Text = toplam.ToString();
        }

        private void btnFiltrele_Click(object sender, EventArgs e)
        {
            TabloyuDoldur();
        }
    }
}
